package pikes.ecma;

public class Addition extends PrintableExpression implements IAdditiveExpression {

	private IAdditiveExpression first = null;

	private IMultiplicativeExpression second = null;

	public Addition(final CharSequence first, final CharSequence second) {
		this(new Identifier(first), new Identifier(second));
	}

	public Addition(final IAdditiveExpression first, final IMultiplicativeExpression second) {
		super();
		this.first = first;
		this.second = second;
	}

	public void visit(final SyntaxTreeVisitor syntaxTreeVisitor) throws EcmaSyntaxVisitingException {
		first.visit(syntaxTreeVisitor);
		syntaxTreeVisitor.binaryOperator("+");
		second.visit(syntaxTreeVisitor);
	}

	@Override
	public boolean equals(final Object obj) {
		if (obj instanceof Addition) {
			Addition thatAddition = (Addition) obj;
			if (!first.equals(thatAddition.first)) {
				return false;
			}

			if (!second.equals(thatAddition.second)) {
				return false;
			}

			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return first.hashCode() + second.hashCode();
	}

}
